package cn.cdeden.knowledge.service;

import cn.cdeden.common.core.utils.page.TableDataInfo;
import cn.cdeden.knowledge.domain.EnterprisePerm;
import cn.cdeden.knowledge.domain.dto.EnterprisePermQueryParam;
import cn.cdeden.knowledge.domain.vo.EnterpriseMemberVo;
import cn.cdeden.knowledge.domain.dto.EnterprisePermDto;
import cn.cdeden.knowledge.enums.PermTypeEnum;
import cn.cdeden.system.api.domain.enums.EnterprisePermTypeEnum;
import com.baomidou.mybatisplus.extension.service.IService;
import jakarta.validation.constraints.NotNull;
import org.springframework.data.domain.Pageable;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

public interface EnterprisePermService extends IService<EnterprisePerm>{

    @Transactional(rollbackFor = Exception.class)
    int insert(EnterprisePermDto resources);

    List<EnterprisePerm> getPerms(Long parentTreeNodeId, Long userId, EnterprisePermTypeEnum enterprisePermTypeEnum);

    List<Long> getPerms(EnterprisePermQueryParam enterprisePermQueryParam, Long userId, EnterprisePermTypeEnum enterprisePermTypeEnum);

    Boolean extendPerm(Long parentId, Long newTreeId);

    String getPerms(Long treeNodeId, Long userId);

    Boolean checkPermission(Long treeNodeId, EnterprisePermTypeEnum enterprisePermTypeEnum, Long userId);

    public boolean isAdmin(Long userId);

    public boolean isEnterpriseAdmin(Long userId);

    boolean isEnterpriseAdminOrAdmin(Long userId);

    void insertOneFolderPerm(Long treeNodeId, Long parentTreeNodeId, Long userId, EnterprisePermTypeEnum enterprisePermTypeEnum);

    TableDataInfo<EnterpriseMemberVo> selectPermissionsByTreeNodeIdNew(@NotNull Long treeNodeId, String types, String params, String permName, Pageable pageable);

    List<EnterpriseMemberVo> selectPermissionsByTreeNodeIdNew(@NotNull Long treeNodeId, String types, String params, String permName);

    void updatePermissionsByTreeNodeId(@NotNull List<Long> ids, @NotNull String params, @NotNull Long treeNodeId);

    void updateChildrenAllPerm(Long treeNodeId, Long typeId, PermTypeEnum permTypeEnum, EnterprisePermTypeEnum enterprisePermTypeEnum);

    @Transactional(rollbackFor = Exception.class)
    void insertPermissionsByTreeNodeIds(@NotNull List<EnterprisePermDto> enterprisePermDtos, @NotNull Long treeNodeId);

    @Transactional(rollbackFor = Exception.class)
    void deletePermissionsByTreeNodeId(@NotNull List<Long> ids, @NotNull Long treeNodeId);

    void synchronizedChildrenAllPerm(Long treeNodeId) throws InterruptedException;

    @Transactional(rollbackFor = Exception.class)
    void transferPerm(Long transferId, Long targetId);
}
